from sqlalchemy.orm import Session

from app.core.exceptions import ParameterError
from app.models.goods import Goods
from app.models.shop_cart import ShopCart
from app.schemas.order_schemas import OrderCheckoutInput, OrderCheckoutOut


def checkout_order(
        db:Session,
        input: OrderCheckoutInput) -> OrderCheckoutOut:
    """订单核算"""
    cartIds = [int(id) for id in input.cartIds.split(",")]
    cart_list = db.query(ShopCart).filter(ShopCart.id.in_(cartIds)).all()
    if not cart_list:
         raise ParameterError(message="购物车id不正确")
    goods_ids = [cart.goods_id for cart in cart_list]
    goods_list = db.query(Goods).filter(Goods.goods_id.in_(goods_ids)).all()
    